package engine;

import java.awt.Point;

import java.util.List;
import java.util.ArrayList;

import com.golden.gamedev.object.Sprite;

import resources.manager.ResourceManager;
import sprites.EvilFish;

/**
 * Represents a level.
 */
public class Level
{
    private static final String DELIMETER = ",";
    private ResourceManager myManager = ResourceManager.getInstance();
    private int myFishCount;
    private ArrayList<Point> myPoints;
    private double mySpawnx, mySpawny;
    private int myNumberOfPoints;
    private Point myLast;
    private double mySpeed;

    public Level(String level){
        myPoints = new ArrayList<Point>();
        myManager.addResourcesFromFile(level);
        myFishCount = myManager.getInteger("fish_to_save");
        mySpawnx = myManager.getDouble("path_inc_x");
        mySpawny = myManager.getDouble("path_inc_y");
        mySpeed = myManager.getDouble("path_speed");
        myNumberOfPoints = myManager.getInteger("num_path_points");
        myLast = new Point(myManager.getInteger("lastx"),myManager.getInteger("lasty"));
        String[] temp = myManager.getStringArray("points", DELIMETER);
        fillList(temp);
    }
    
    protected double getSpeed(){
    	return mySpeed;
    }

    protected ArrayList<Point> getPoints(){
        return myPoints;
    }

    protected Point getLast(){
        //return myLast;
        return myPoints.get(myPoints.size()-1);
    }

    private void fillList(String[] temp){
        for(int i=0; i<temp.length-1; i=i+2){
            /*
             * The *0.71 and mySpawnx, mySpawny are from ProgBob's original
             * code. Don't ask questions.
             */
            int x = (int)(0.71*(Integer.parseInt(temp[i]) + mySpawnx));
            int y = (int)(0.71*(Integer.parseInt(temp[i+1]) + mySpawny - 10));
            myPoints.add(new Point(x, y));
        }
    }

    /*
     * These methods are required to get some magic values from ProgBob.
     */
    public double getSpawnx()
    {
        return mySpawnx;
    }
    
    public double getSpawny()
    {
        return mySpawny;
    }

}
